import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SupplierClassifyVO, SupplierClassifyForm, SupplierClassifyQuery } from '@/api/goods/classify/types';

/**
 * 查询供应商列表
 * @param query
 * @returns {*}
 */

export const listSupplierClassify = (query?: SupplierClassifyQuery): AxiosPromise<SupplierClassifyVO[]> => {
  return request({
    url: '/order/supplierClassify/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询供应商详细
 * @param id
 */
export const getSupplierClassify = (id: string | number): AxiosPromise<SupplierClassifyVO> => {
  return request({
    url: '/order/supplierClassify/' + id,
    method: 'get'
  });
};

/**
 * 查询供应商详细
 */
export const getClassifyAllList = (query: any): AxiosPromise<SupplierClassifyVO> => {
  return request({
    url: '/order/supplierClassify/allList',
    method: 'get',
    params: query
  });
};

/**
 * 查询供应商树
 */
export const getClassifyTree = (classifyType: string | number | Array<string | number>) => {
  return request({
    url: '/order/supplierClassify/supplierClassifyTree/' + classifyType,
    method: 'get'
  });
};
/**
 * 查询供应商详细
 */
export const findSortByType = (type: String | Number): AxiosPromise<SupplierClassifyVO> => {
  return request({
    url: '/order/supplierClassify/findSortByType/' + type,
    method: 'get',
  });
};

/**
 * 新增供应商
 * @param data
 */
export const addSupplierClassify = (data: SupplierClassifyForm) => {
  return request({
    url: '/order/supplierClassify',
    method: 'post',
    data: data
  });
};

/**
 * 修改供应商
 * @param data
 */
export const updateSupplierClassify = (data: SupplierClassifyForm) => {
  return request({
    url: '/order/supplierClassify',
    method: 'put',
    data: data
  });
};

/**
 * 删除供应商
 * @param id
 */
export const delSupplierClassify = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/supplierClassify/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param goodsSupplierClassifyId 客户端id
 * @param status 状态
 */
export function changeStatus(goodsSupplierClassifyId: string, status: string) {
  const data = {
    goodsSupplierClassifyId,
    status
  };
  return request({
    url: '/order/supplierClassify/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list: listSupplierClassify,
  get: getSupplierClassify,
  add: addSupplierClassify,
  update: updateSupplierClassify,
  del: delSupplierClassify,
  getClassifyAllList: getClassifyAllList,
  getClassifyTree: getClassifyTree,
  findSortByType: findSortByType,
}